﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;

using Subgurim.Controles;

namespace BL
{
    public class StoreBL
    {
        public GMap LoadStoresOnMap(GMap gmap)
        {
            View.Services.StoreService storeService = new View.Services.StoreService();

            XmlNode storesXML = storeService.GetStoresInfo();

            MarkerManager markerManager = new MarkerManager();


            string storeName;
            double latitude;
            double longitude;
            string contactName;
            string phoneNumber;
            string street;
            string zip;
            GIcon icon3 = new GIcon();
            foreach (XmlNode store in storesXML.ChildNodes)
            {
                if (store.Name == "Store")
                {

                    // Moet wat aan de o.o latitudes gedaan worden vandaar ook de try en catch sommige hebben geen geocode
                    try
                    {
                        storeName = store["Name"].InnerText;
                        XmlNode address = store["Address"];
                        latitude = Convert.ToDouble(address["Latitude"].InnerText);
                        longitude = Convert.ToDouble(address["Longitude"].InnerText);
                        street = address["AddressLine1"].InnerText;
                        zip = address["Postalcode"].InnerText;

                    }
                    catch (Exception e) { continue; }
                    GLatLng point  = new GLatLng(latitude, longitude);

                    icon3.flatIconOptions = new FlatIconOptions(25, 25, Color.Red, Color.Black, "B", Color.White, 15,
                                                                FlatIconOptions.flatIconShapeEnum.roundedrect);
                    GMarker marker = new GMarker(point);
                    GInfoWindow info = new GInfoWindow(marker, @"<b>Store Name:</b> "+storeName +
                        "<br/>Street: "+street+
                        "<br/>Zip: "+zip);
                    gmap.addGMarker(marker);
                    gmap.Add(info);
                    markerManager.Add(marker, 6);
                    markerManager.Add(info, 5);

                }









                else
                {
                    throw new FormatException("Xml is wrong formatted");
                }

            }


            return gmap;
            //XmlTextReader reader = new XmlTextReader(stores);
            //MarkerManager markerManager = new MarkerManager();

            //foreach (Store store in StoresList)
            //{

            //    //Double lat ;
            //    //Double lng ;
            //    //GLatLng point = new GLatLng(lat, lng);
            //    //GIcon icon3 = new GIcon();
            //    //icon3.flatIconOptions = new FlatIconOptions(25, 25, Color.Red, Color.Black, "B", Color.White, 15,
            //    //                                            FlatIconOptions.flatIconShapeEnum.roundedrect);
            //    //GMarker marker = new GMarker(point, icon3);

            //    //GInfoWindow info = new GInfoWindow(marker, "Store Name: " + store.storeName.ToString()
            //    //                                        + "<br/> Address: " + store.Address1.ToString());
            //    ////GMap1.addGMarker(marker);
            //    //GMap1.Add(info);
            //    //markerManager.Add(marker, 6);
            //    //markerManager.Add(info, 5);
            //}
            //gmap.markerManager = markerManager;
            //return gmap;

        }
    }
}
